﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_HappyClubSrhForm
 * 类型：       控制层
 * 功能说明：   快乐管家-兴趣小组检索页面
 * 作者：       郭晓庆
 * 创建日期：   2007/09/12
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.System;
using log4net;
using Shpm.App.Commons.Utils;
using Shpm.App.Master.Dao;

public partial class App_Input_HappyClubSrhForm : System.Web.UI.Page
{
    // log
    protected static ILog log = LogManager.GetLogger(typeof(App_Input_HappyClubSrhForm));
  
    // page load
    protected void Page_Load(object sender, EventArgs e)
    {        
        if (!Page.IsPostBack)
        {
            //俱乐部下拉列表邦定
            CommonDictionaryBean dataBean = new CommonDictionaryBean();
            CommonDictionaryDao Dao = new CommonDictionaryDao();
            dataBean.Catalog = "T_INTEREST_INTEREST_TYPE";
            IList list = Dao.FindByCatalog(dataBean);
            if(list != null && list.Count >0)
            {
                list.Insert(0,new CommonDictionaryBean());
            }
            this.dropInterestType.DataSource = list;
            this.dropInterestType.DataBind();

            if (Context.Items.Contains("HidCommand"))
            {
                ViewState["HidInterestName"]=Context.Items["HidInterestName"];
                ViewState["HidInterestType"]=Context.Items["HidInterestType"];
                ViewState["HidLeadName"]    =Context.Items["HidLeadName"];
                ViewState["HidCommand"] = Context.Items["HidCommand"];
                ViewState["HidPageIndex"] = Context.Items["HidPageIndex"];

                this.txtInterestName.Text = Convert.ToString(Context.Items["InpInterestName"]);
                this.txtLeadName.Text = Convert.ToString(Context.Items["InpLeadName"]);
                this.dropInterestType.SelectedValue = Convert.ToString(Context.Items["InpInterestType"]);
                InitHappyClub();
            }
        }
    }

    private void InitHappyClub()
    {
        HappyClubDao dao = new HappyClubDao();
        HappyClubBean bean = new HappyClubBean();
        bean.InterestName = Convert.ToString(ViewState["HidInterestName"]);
        bean.LeadName = Convert.ToString(ViewState["HidLeadName"]);
        bean.InterestType =  Convert.ToString(ViewState["HidInterestType"]);
        IList list = dao.FindInterest(bean);
        if (ViewState.IsItemDirty("HidPageIndex"))
        {
            this.GridView1.PageIndex = Convert.ToInt32(ViewState["HidPageIndex"]);
            ViewState.Remove("HidPageIndex");
        }
       
        this.GridView1.DataSource = list;
        this.GridView1.DataBind();

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 设置分页编号
        GridView1.PageIndex = e.NewPageIndex;
        InitHappyClub();
    }
    protected void ImageButton_Command(object sender, CommandEventArgs e)
    {
        string directUrl;
        switch (e.CommandName)
        {
            case "DETAIL":   // 编辑
                directUrl = "~/App/Input/HappyClubUpdForm.aspx";
                break;
            case "MEMBER": // 审核
                directUrl = "~/App/Input/HappyClubMemberUpdForm.aspx";
                break;
            
            default:
                directUrl = "~/App/Input/HappyClubSrhForm.aspx";
                break;
        }

        // Transfer Page        
        Context.Items["INTEREST_ID"] = Convert.ToString(e.CommandArgument);
        gotoPage(directUrl);
    }
    // 参数传递 and 页面迁移
    private void gotoPage(string url)
    {
        // 传递控件输入内容
        Context.Items["InpInterestName"]    = txtInterestName.Text.Trim();
        Context.Items["InpInterestType"]    = dropInterestType.SelectedValue;
        Context.Items["InpLeadName"]        = txtLeadName.Text.Trim();


        // 传递检索条件
        Context.Items["HidInterestName"]    = Convert.ToString(ViewState["HidInterestName"]);
        Context.Items["HidInterestType"]    = Convert.ToString(ViewState["HidInterestType"]);
        Context.Items["HidLeadName"]        = Convert.ToString(ViewState["HidLeadName"]);
        Context.Items["HidCommand"]         = Convert.ToString(ViewState["HidCommand"]);

        // 传递分页编号
        Context.Items["HidPageIndex"] = GridView1.PageIndex;
        ControllerUtils.Transfer(Context, url, true);
    }

    protected void search_Click(object sender, EventArgs e)
    {
        ViewState["HidInterestName"]    = txtInterestName.Text.Trim();
        ViewState["HidInterestType"]    = dropInterestType.SelectedValue;
        ViewState["HidLeadName"]        = txtLeadName.Text.Trim();
        ViewState["HidCommand"]         = "SEARCH";
        ViewState["HidPageIndex"] = 0;

        //gridview
        InitHappyClub();
    }


    protected void btnNew_Click(object sender, EventArgs e)
    {
        string directUrl = "~/App/Input/HappyClubUpdForm.aspx";
        gotoPage(directUrl);
    }
}
